/*
 * @lc app=leetcode.cn id=476 lang=typescript
 *
 * [476] 数字的补数
 */

// @lc code=start
function findComplement(num: number): number {
    if (num === 1) return 0;
    let map = {
        "1": "0",
        "0": "1",
    };
    const data = num
        .toString(2)
        .split("")
        .map((i) => {
            return map[i as "0" | "1"];
        })
        .join("");
    return parseInt(data, 2);
}
// @lc code=end
